<template>
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
        <div class="Home">
            <div class="Home_bar">
                <van-notice-bar :left-icon="PicUrl" :scrollable="false" background="rgba(255, 255, 255, 0.2)"
                    color="rgba(255, 255, 255, 1)">
                    <van-swipe vertical class="notice-swipe" :autoplay="3000" :touchable="false" loop
                        :show-indicators="false">
                        <van-swipe-item :key="index" v-for="(shopItem, index) in NoticeList">
                            <p>{{ shopItem.Contents }}</p>
                        </van-swipe-item>
                    </van-swipe>
                </van-notice-bar>
            </div>
            <div class="Home_banner">
                <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white" :showIndicators="false">
                    <van-swipe-item :key="index" v-for="(Item, index) in ImageList">
                        <img :src="Item.PicUrl" alt="">
                    </van-swipe-item>
                </van-swipe>
            </div>
            <div class="Home_PickWeek">
                <div class="titel">
                    <p> 公司介绍 </p>
                    <div class="Home_Groupla" @click="GrouplaIs = true">
                        <img src="@/assets/img/Home/m1.png" alt="">
                        <span> 扫码进官方群 </span>
                    </div>
                </div>

            </div>
            <div class="Home_luckdraw" @click="goLuckdraw()">
                <img src="@/assets/img/Home/re.png" alt="">
            </div>
            <van-overlay :show="GrouplaIs">
                <div class="Home_wrapper" @click="GrouplaIs = false">
                    <van-icon name="cross" class="Home_cross" />
                    <div class="img"><img :src="GrouplaUrl.PicUrl" alt=""></div>
                    <p> 扫码加入官方群 </p>
                </div>
            </van-overlay>
        </div>
    </van-pull-refresh>
</template>

<script>
import { onMounted, reactive, ref, toRefs } from 'vue'
import { Toast, Notify } from 'vant';
import { useStore } from "vuex"; // ⚪️ 引入状态管理
import router from "@/router";
import { GetNoticeList, GetImageList, GetFXImageList } from "@/network/home";
import { GetProductList } from "@/network/order";
import PicUrl from '@/assets/img/Home/left-icon.png'
export default {
    setup() {
        const state = reactive({
            isLoading: false,
            GrouplaUrl: '',
            GrouplaIs: false,
            NoticeList: [],
            ImageList: [],
            ProductList: [],
            PicUrl: PicUrl
        })
        onMounted(() => {
            init();
        });
        // 初始化信息
        const init = () => {
            // 公告列表
            GetNoticeList({
                pageSize: 3,
                currentPage: 1
            }).then((res) => {
                var data = res.Data;
                state.NoticeList = data
            });
            // 二维码
            GetFXImageList({
                len: 1,
            }).then((res) => {
                var data = res.Data;
                console.log(data)
                state.GrouplaUrl = data[0]
            });
            // 获取轮播图
            GetImageList({
                len: 2,
            }).then((res) => {
                var data = res.Data;
                console.log(data)
                state.ImageList = data
            });
        };
        const goProductDetails = (ID) => {
            if (window.requesTag) {
                router.push({ path: "/ProductDetails", query: { id: ID, date: new Date().getTime() } });
            } else {
                router.push({ path: "/ProductDetailsH5", query: { id: ID, date: new Date().getTime() } });
            }
        };
        const goLuckdraw = () => {
            router.push({
                path: "/luckdraw",
                query: {
                    date: new Date().getTime()
                }
            });
        };
        const onRefresh = () => {
            init()
            state.isLoading = false
        }
        return {
            ...toRefs(state),
            goProductDetails,
            goLuckdraw,
            onRefresh
        };
    },
};
</script>

<style scoped></style>